<?php
$row = array();
$i = 0;

if (!empty($flats)) {
    foreach ($flats as $key => $flat) {
        if ($key % 4 == 0) {
            $i++;
        }
        $row[$i][] = $flat;
    }
}
?>


<div class="row">
    <div class="span12">
        <?php if(!empty($city)){ ?>
            <h1 class="page-header"><?= $city->сountry->name . ", " . $city->region->name . ", " . $city->name; ?></h1>
        <?php } else { ?>
            <h1 class="page-header">Новые предложения</h1>
        <?php } ?>
        <div class="properties-grid">
            <?php if (!empty($flats)) { ?>
                <?php foreach ($row as $flats) { ?>
                    <div class="row" style="margin-bottom: 20px;">
                        <?php foreach ($flats as $flat) { ?>
                            <div class="property span3">
                                <div class="image">
                                    <div class="content">
                                        <a href="<?= $flat->сity->url . "/" . $flat->id; ?>"></a>
                                        <?= ImageResizer::getThumb($flat->img0, 'data/imgs/flat/' . $flat->id . '/', $flat->img0, 270, 200); ?>
                                    </div><!-- /.content -->

                                    <div class="price"><?= $flat->price; ?> грн./сутки</div><!-- /.price -->
                                    <!--<div class="reduced">Reduced </div>--><!-- /.reduced -->
                                </div><!-- /.image -->

                                <div class="title">
                                    <h2><a href="<?= $flat->сity->url . "/" . $flat->id; ?>"><?= $flat->street . " " . $flat->home; ?></a></h2>
                                </div><!-- /.title -->

                                <div class="location"><?= $flat->сountry->name . ", " . $flat->region->name . ", " . $flat->сity->name; ?></div><!-- /.location -->
                                <?php /*
                                  <div class="area">
                                  <span class="key">Тип:</span><!-- /.key -->
                                  <span class="value"><?= $flat->getTypeFlatText(); ?></span><!-- /.value -->
                                  </div><!-- /.area -->

                                  <div class="bedrooms"><div class="content">4</div></div><!-- /.bedrooms -->
                                  <div class="bathrooms"><div class="content">3</div></div><!-- /.bathrooms -->
                                 * 
                                 */ ?>
                            </div><!-- /.property -->
                        <?php } ?>
                    </div><!-- /.row --> 
                <?php } ?>


            <?php } else { ?>
                Данный раздел пока не содержит ни одного объекта!
            <?php } ?>

        </div><!-- /.properties-grid -->
    </div>
    <?php if(0) { ?>
    <div class="sidebar span3">
        <div class="widget our-agents">
            <div class="title">
                <h2>Our Agents</h2>
            </div><!-- /.title -->

            <div class="content">
                <div class="agent">
                    <div class="image">
                        <img src="/themes/realia/img//photos/emma-small.png" alt="">
                    </div><!-- /.image -->
                    <div class="name">Victoria Summer</div><!-- /.name -->
                    <div class="phone">333-666-777</div><!-- /.phone -->
                    <div class="email"><a href="mailto:victoria@example.com">victoria@example.com</a></div><!-- /.email -->
                </div><!-- /.agent -->

                <div class="agent">
                    <div class="image">
                        <img src="/themes/realia/img//photos/john-small.png" alt="">
                    </div><!-- /.image -->
                    <div class="name">John Doe</div><!-- /.name -->
                    <div class="phone">111-222-333</div><!-- /.phone -->
                    <div class="email"><a href="mailto:john.doe@example.com">victoria@example.com</a></div><!-- /.email -->
                </div><!-- /.agent -->
            </div><!-- /.content -->
        </div><!-- /.our-agents -->
        <div class="hidden-tablet">
            <div class="widget properties last">
                <div class="title">
                    <h2>Latest Properties</h2>
                </div><!-- /.title -->

                <div class="content">
                    <div class="property">
                        <div class="image">
                            <a href="detail.html"></a>
                            <img src="/themes/realia/img//tmp/property-small-4.png" alt="">
                        </div><!-- /.image -->

                        <div class="wrapper">
                            <div class="title">
                                <h3>
                                    <a href="detail.html">27523 Pacific Coast</a>
                                </h3>
                            </div><!-- /.title -->
                            <div class="location">Palo Alto CA</div><!-- /.location -->
                            <div class="price">€2 300 000</div><!-- /.price -->
                        </div><!-- /.wrapper -->
                    </div><!-- /.property -->

                    <div class="property">
                        <div class="image">
                            <a href="detail.html"></a>
                            <img src="/themes/realia/img//tmp/property-small-5.png" alt="">
                        </div><!-- /.image -->

                        <div class="wrapper">
                            <div class="title">
                                <h3>
                                    <a href="detail.html">27523 Pacific Coast</a>
                                </h3>
                            </div><!-- /.title -->
                            <div class="location">Palo Alto CA</div><!-- /.location -->
                            <div class="price">€2 300 000</div><!-- /.price -->
                        </div><!-- /.wrapper -->
                    </div><!-- /.property -->

                    <div class="property">
                        <div class="image">
                            <a href="detail.html"></a>
                            <img src="/themes/realia/img//tmp/property-small-6.png" alt="">
                        </div><!-- /.image -->

                        <div class="wrapper">
                            <div class="title">
                                <h3>
                                    <a href="detail.html">27523 Pacific Coast</a>
                                </h3>
                            </div><!-- /.title -->
                            <div class="location">Palo Alto CA</div><!-- /.location -->
                            <div class="price">€2 300 000</div><!-- /.price -->
                        </div><!-- /.wrapper -->
                    </div><!-- /.property -->

                    <div class="property">
                        <div class="image">
                            <a href="detail.html"></a>
                            <img src="/themes/realia/img//tmp/property-small-2.png" alt="">
                        </div><!-- /.image -->

                        <div class="wrapper">
                            <div class="title">
                                <h3>
                                    <a href="detail.html">27523 Pacific Coast</a>
                                </h3>
                            </div><!-- /.title -->
                            <div class="location">Palo Alto CA</div><!-- /.location -->
                            <div class="price">€2 300 000</div><!-- /.price -->
                        </div><!-- /.wrapper -->
                    </div><!-- /.property -->
                </div><!-- /.content -->
            </div><!-- /.properties -->
        </div>
    </div>
    <?php } ?>
</div>